##########################################
## Copyright 2012-2013 Ceruti Francesco
##
##
## This file is part of LiSP (Linux Show Player).
##
## LiSP (Linux Show Player) is free software: you can redistribute it and/or modify
## it under the terms of the GNU Lesser General Public License as published by
## the Free Software Foundation, either version 3 of the License, or
## (at your option) any later version.
##
## LiSP (Linux Show Player) is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU Lesser General Public License for more details.
##
## You should have received a copy of the GNU Lesser General Public License
## along with LiSP (Linux Show Player).  If not, see <http://www.gnu.org/licenses/>.
##########################################

from lisp.utils import configuration as cfg

PLUGINS_LIST = cfg.config['Plugins']['Packages'].split(',')

for mod in PLUGINS_LIST:
    exec('from . import ' + mod)


def initPlugins(main, debug=False):
    plugins = []
    err = ''
    for plug in PLUGINS_LIST:
        if(debug):
            plugins.append(eval(plug + '.build(main)'))
        else:
            try:
                plugins.append(eval(plug + '.build(main)'))
            except:
                err += plug + '\n'

    if(err != ''):
        raise Exception('Plugins init failed:\n\n' + err[:-1])

    return plugins
